package com.nosweattechnet.server;

import java.util.concurrent.ExecutionException;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

public class PlaceMapAsyncTask extends CommunicatorAsyncTask {

	private BasicNameValuePair tag=new BasicNameValuePair("tag","getPlaceMapByID");
	private String placeMapIDString="placemap_uuid";
	
	//Creates a new Async task and adds the associated values to the name value pairs
	public PlaceMapAsyncTask(String placeid) {
		super();
		super.addNameValuePair(tag);
		super.addNameValuePair(new BasicNameValuePair(placeMapIDString,placeid));
	}

	//This returns the image for the Place map with the given id
	public Bitmap getPlaceMapbyID() throws InterruptedException, ExecutionException{
		JSONArray jarr=this.get();
		
		if(jarr.length()!=1){
			return null;
		}
		Bitmap img_bitmap=null;
		String obj=null;
		try {
			obj = jarr.getString(0);
			byte[] decodedString = Base64.decode(obj.getBytes(), Base64.DEFAULT);
			img_bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return img_bitmap;
		}
}


